local skel = fk.CreateSkill {
  name = "emo__qiangjinjiu",
}

Fk:loadTranslationTable{
  ["emo__qiangjinjiu"] = "将进酒",
  [":emo__qiangjinjiu"] = "准备阶段，你可摸一牌，然后可摸一牌，然后可摸一牌。你优先使用这些实体手牌。",

  ["#emo__qiangjinjiu-ask"] = "将进酒：你可以摸一张牌（第%arg次，共3次）",
  ["@@emo__qiangjinjiu-inhand"] = "将进酒",

  ["$emo__qiangjinjiu1"] = "直抒胸臆，酣畅淋漓。",
  ["$emo__qiangjinjiu2"] = "万物一言，方有大气象。",
}

skel:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function (self, event, target, player, data)
    return player:hasSkill(skel.name) and target == player and player.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#emo__qiangjinjiu-ask:::1" })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    player:drawCards(1, skel.name, nil, "@@emo__qiangjinjiu-inhand")
    for i = 2, 3 do
      if player.dead or not room:askToSkillInvoke(player, { skill_name = skel.name, prompt = "#emo__qiangjinjiu-ask:::"..i }) then
        break
      end
      player:broadcastSkillInvoke(skel.name, i-1)
      player:drawCards(1, skel.name, nil, "@@emo__qiangjinjiu-inhand")
    end
  end,
})

skel:addEffect("prohibit", {
  prohibit_use = function (self, player, card)
    if card:isVirtual() then return false end-- 虚拟牌不受限制
    local markIds = table.filter(player.player_cards[Player.Hand], function (id)
      return Fk:getCardById(id):getMark("@@emo__qiangjinjiu-inhand") ~= 0
    end)
    if #markIds == 0 then return false end -- 全是普通牌，不受限制
    if table.contains(markIds, card.id) then return false end
    local room = Fk:currentRoom()
    if room.QjjDrinking then return false end -- 防止自循环调用，有点危险，但是没办法
    room.QjjDrinking = true
    local check = false
    if Fk.currentResponsePattern == nil then
      if table.find(markIds, function (id) return player:canUse(Fk:getCardById(id)) end) then
        check = true
      end
    else
      if table.find(markIds, function (id) return Exppattern:Parse(Fk.currentResponsePattern):match(Fk:getCardById(id)) end) then
        check = true
      end
    end
    room.QjjDrinking = nil
    return check
  end,
})

skel:addLoseEffect(function (self, player, is_death)
  for _, id in ipairs(player.player_cards[Player.Hand]) do
    if Fk:getCardById(id):getMark("@@emo__qiangjinjiu-inhand") ~= 0 then
      player.room:setCardMark(Fk:getCardById(id), "@@emo__qiangjinjiu-inhand", 0)
    end
  end
end)

return skel
